package test;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;

public class XpathByMavenPom {
	static XPath xpath; 
	public static void main(String[] args) throws Exception {
		XPathFactory factory = XPathFactory.newInstance();
		xpath = factory.newXPath();
		DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = domFactory.newDocumentBuilder();
		String filePath = "G:\\99无限\\20160612_ihealth_Code_all\\i-admin\\pom.xml";
		Document document = builder.parse(new File(filePath));
		
		String artifactId = (String) xpath.evaluate("/project/artifactId", document,  XPathConstants.STRING);
		System.out.println(artifactId);
	}
}
